package com.yowasa.xiuxian.engine.battle.strategy.drop.all;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import com.yowasa.xiuxian.annoations.BS;
import com.yowasa.xiuxian.constant.XiuxianConstants;
import com.yowasa.xiuxian.engine.battle.strategy.BaseDefendStrategy;
import com.yowasa.xiuxian.engine.battle.strategy.BaseSpellStrategy;
import com.yowasa.xiuxian.engine.battle.strategy.BattleStrategy;
import com.yowasa.xiuxian.entity.bo.battle.BattleContent;
import com.yowasa.xiuxian.entity.bo.battle.BuffContent;
import com.yowasa.xiuxian.entity.bo.battle.UserBattleContent;
import com.yowasa.xiuxian.entity.bo.user.UserBO;
import com.yowasa.xiuxian.entity.enums.ElementEnum;
import com.yowasa.xiuxian.exception.HandlerException;
import com.yowasa.xiuxian.service.helper.BattleHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Map;
import java.util.Set;

@BS(name = "机兵列阵")
@Order(502)
@Component
public class JiBinLieZhen extends BaseDefendStrategy {
    @Autowired
    private BattleHelper battleHelper;

    @Override
    public ElementEnum getElement() {
        return null;
    }
    @Override
    public int defend(UserBattleContent user, UserBattleContent battleUser, BattleStrategy bs, int dmg, BattleContent content) {
        Object flag = user.getFlag().get("机兵列阵");
        if(ObjectUtil.isNull(flag) && user.getBattleInfo().getChp() < user.getBattleInfo().getHp() * 0.3){
            user.getFlag().put("机兵列阵","1111");
            user.getBattleInfo().setChp(user.getBattleInfo().getHp());
            user.getBattleInfo().setCmp(user.getBattleInfo().getMp());

            Map<String, Integer> cd = user.getCd();
            Set<String> strings = cd.keySet();
            String key = RandomUtil.randomEle(Arrays.asList(strings.toArray(new String[0])));
            user.getCd().remove(key);
        }
        if(ObjectUtil.isNotNull(flag)){
            return dmg*2;
        }
        return dmg;
    }
    @Override
    public void limit(UserBO user) {
        if (user.getStage() < 5) {
            throw new HandlerException("学习/使用机兵列阵阶位需要在如耀之金以上");
        }

    }

    @Override
    public String limitDesc() {
        return "学习/使用机兵列阵阶位需要在如耀之金以上";
    }

    @Override
    public String desc() {
        return "生命值首次降低到30%以下时会触发，hp与mp回复至满状态，随机清除一项战技cd，但受到的伤害会翻倍";
    }

}
